<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            height: 100px;
            width: 100px;
            background-color: mediumslateblue;
            position: absolute;
        }
    </style>
</head>

<body>
    <div class="box"></div>
</body>
<script>
    //核心算法： (目标值 - 现在的位置 )   /   10    做为每次移动的距离 步长
    //1s. 200-0/10 =20
    //2s. 200-20/10 =18
    //3s . 200-38/10 = 16.2
    var box = document.querySelector('.box');
    var target = 200;
    var a1 = setInterval(function() {
        if (box.offsetLeft > 200 || box.offsetLeft == 200) {
            clearInterval(a1);
        } else {
            var movespace = (target - box.offsetLeft) / 10;
            movespace = movespace > 0 ? Math.ceil(movespace) : 0;
            console.log(movespace);
            var targetMove = box.offsetLeft + movespace;
            box.style.left = targetMove + "px";
        }
    }, 30)
</script>

</html>